<template>
    <div class="screen" :id='id'></div>
</template>

<script>
let DHPlayerObj = null
import DHPlayer from '@/utils/player/DHPlayer';
import { getCameraPlayUrl } from '@/api/index.js'
export default {
    props: {
        id: {
            typeof: String
        },
        channelCode: {
            typeof: String
        }
    },
    methods: {
        startPlayer() {
            getCameraPlayUrl({"channelCode": this.channelCode}).then(res => {
                if (!res.data) return;
                if (!DHPlayerObj) {
                    console.log("不能播放，请先初始化！！！！！");
                    return;
                }
                DHPlayerObj.startPlayer(res.data.url);
            })
        },
    },
    mounted() {
        setTimeout(() => {
            DHPlayerObj = new DHPlayer(this.id)
            this.startPlayer()
        }, 200)
    },
    destroyed() {
        DHPlayerObj?.destroy()
    }
}
</script>

<style lang="less" scoped>
.screen {
    width: 100%;
    height: 100%;
}
</style>
